//
//  KeyFrameViewController.m
//  Animation
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "KeyFrameViewController.h"

@interface KeyFrameViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *plan;

@end

@implementation KeyFrameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //沿着关键路径移动
    CGMutablePathRef planePath = CGPathCreateMutable();
    CGPathMoveToPoint(planePath, NULL, 160.0, 100.0);
    CGPathAddLineToPoint(planePath, NULL, 100.0, 280.0);
    CGPathAddLineToPoint(planePath, NULL, 150.0, 260.0);
    CGPathAddLineToPoint(planePath, NULL, 200.0, 200.0);
    CGPathAddLineToPoint(planePath, NULL, 60.0, 200.0);
    CGPathAddLineToPoint(planePath, NULL, 170.0, 280.0);
    CGPathCloseSubpath(planePath);
    
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    [anim setPath:planePath];//设定路径
    anim.duration = 3;
    [self.plan.layer addAnimation:anim forKey:nil];
    
    //释放
    CFRelease(planePath);
    planePath = nil;
    
//    2.设定关键时间点，及关键时间点对应的值
    CAKeyframeAnimation *anim2 = [CAKeyframeAnimation animationWithKeyPath:@"transfrom.scale"];
    anim2.duration = 3;
    anim2.keyTimes = @[@0.2,@0.4,@0.6,@0.8,@1];//时间0~1
    anim2.values = @[@0.25,@1,@0.5,@1,@2];//对应时间点的值是多少
    [self.plan.layer addAnimation:anim2 forKey:nil];
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
